package com.example.demo.consumer.service.impl;

import com.example.demo.common.domain.ChannelRead;
import com.example.demo.consumer.config.ActiveMqConfig;
import com.example.demo.consumer.service.ListenerService;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Auther Created by l.wang on 2019/4/4.
 */
@Service
public class ListenerServiceImpl implements ListenerService {

    private ActiveMqConfig.ServiceEventSource serviceEventSource;

    public ListenerServiceImpl(ActiveMqConfig.ServiceEventSource serviceEventSource) {
        this.serviceEventSource = serviceEventSource;
    }

    @Override
    public void disPoseService(ChannelRead msg) {
        try {
            System.out.println("处理："+Thread.currentThread().getName());
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        msg.setMsg("回馈成功");
        System.out.println(msg.getCode());
        serviceEventSource.publishToConnectServer(msg);
    }
}
